<template>
	<view class="container container24934">
		<view class="flex flex-wrap diygw-col-24 flex-direction-column flex-clz">
			<view v-for="(item,index) in datarows" :key="index" class="flex diygw-col-24 flex-nowrap flex1-clz">
				<view class="flex flex-wrap diygw-col-6 flex-direction-column justify-center items-center">
					<view class="flex diygw-col-14">
						<view class="diygw-avatar radius bg-none">
							<image mode="aspectFit" class="diygw-avatar-img radius" src="/static/user/avatar.png">
							</image>
						</view>
					</view>
				</view>
				<view class="flex flex-wrap diygw-col-12 flex-direction-column justify-center items-center">
					<view class="diygw-col-24 text1-clz"> {{ item.username }} </view>
					<view class="diygw-col-24 text-clz"> {{ item.telephone }} </view>
				</view>
				<view class="flex flex-wrap diygw-col-6 flex-direction-column justify-center items-center">
					<view v-if="item.status==2" class="flex diygw-col-24">
						<button class="diygw-btn orange radius-xs flex-sub margin-xs button-button-clz" @click="updateStatus(item.id)">同意</button>
					</view>
					<view v-if="item.status==1" class="flex diygw-col-24">
						<button class="diygw-btn diygw-line-orange radius-xs flex-sub margin-xs button-button-clz">已同意</button>
					</view>
					<view v-if="item.status==0" class="flex diygw-col-24">
						<button class="diygw-btn diygw-line-orange radius-xs flex-sub margin-xs button-button-clz">已拒绝</button>
					</view>
				</view>
			</view>
		</view>

		<view class="clearfix"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				//页面传参
				globalOption: {},
				//自定义全局变量
				globalData: {},
				id: '',
				page: 1,
				size: 10,
				datarows: [],
				count: 0,

			};
		},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}
			this.id = option.id
			this.init();
		},
		methods: {
			async init() {
				this.resultApi()
			},
			async resultApi() {
				const page = this.page
				const size = this.size
				const order_id = this.id
				const type = 'adopt'
				const data = {
					'orderId': order_id,
					'type': type
				}
				const http_url = '/orderUser/getUser/' + page + '/' + size
				const result =await this.$http.get(http_url, data)
				const code = result.code
				if(code==200){
					const data = result.data.records
					this.count = result.data.total
					this.datarows = this.datarows.concat(data)
				}
				
			},
			async updateStatus(userid){
				const order_id = this.id
				const data={
					"orderId":order_id,
					"userId":userid,
					"type":"adopt",
					"status":1
				}
				const header={
					'content-type': 'application/json;charset=UTF-8',
				}
				const http_url='/orderUser/updateStatus'
				const result = await this.$http.put(http_url,data,header)
				const code = result.code
				if(code==200){
					uni.showToast({
						title: '已同意',
						icon: 'success',
						duration: 2000
					});
					uni.redirectTo({
						url:'/pages/user/deliver/index'
					})
				}
			}

		},
		onReachBottom() {
			if (this.datarows.length < this.count) {
				this.page++;
				this.getListByTypeId(this.tabsIndex - 1)
			}
		
		},
		onPullDownRefresh() {
			this.init()
		},
	};
</script>

<style lang="scss" scoped>
	.flex-clz {
		margin-left: 10rpx;
		padding-top: 10rpx;
		padding-left: 10rpx;
		width: calc(100% - 10rpx - 10rpx) !important;
		padding-bottom: 10rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
		padding-right: 10rpx;
	}

	.flex1-clz {
		padding-top: 10rpx;
		border-bottom-left-radius: 20rpx;
		overflow: hidden;
		padding-left: 10rpx;
		padding-bottom: 10rpx;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
		padding-right: 10rpx;
	}

	.text1-clz {
		margin-left: 10rpx;
		font-weight: bold;
		width: calc(100% - 10rpx - 10rpx) !important;
		font-size: 34rpx !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}

	.text-clz {
		margin-left: 10rpx;
		font-weight: bold;
		width: calc(100% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}

	.button-button-clz {
		margin: 6rpx !important;
	}

	.container24934 {
		padding-left: 0px;
		padding-right: 0px;
	}

	.container24934 {}
</style>